﻿#pragma once

#include "RBTree.h"

void TestRBTree1()
{
	RBTree<int, int> t;
	// 常规的测试⽤例
	//int a[] = { 16, 3, 7, 11, 9, 26, 18, 14, 15 };
	// 特殊的带有双旋场景的测试⽤例
	int a[] = { 4, 2, 6, 1, 3, 5, 15, 7, 16, 14 };
	for (auto e : a)
	{
		t.Insert({ e, e });
	}
	t.InOrder();
	cout << t.IsBalance() << endl;
}

// 插⼊⼀堆随机值，测试平衡，顺便测试⼀下⾼度和性能等
void TestRBTree2()
{
	const int N = 100;
	vector<int> v;
	v.reserve(N);
	//srand(time(0));
	for (size_t i = 0; i < N; i++)
	{
		v.push_back(rand() + i);
	}
	RBTree<int, int> t;
	int i = 0;
	for (auto e : v)
	{
		t.Insert(make_pair(e, e));
		//cout << 'e' << ':' << e << " IsBalance: " << t.IsBalance() << " i: " << ++i << endl;
	}
	cout << t.IsBalance() << endl;

	//size_t begin1 = clock();
	// 确定在的值
	//for (auto e : v)
	//{
	//	t.Find(e);
	//}
	//// 随机值
	////for (size_t i = 0; i < N; i++)
	////{
	////	t.Find((rand() + i));
	////}
	//size_t end1 = clock();
	//cout << "Find:" << end1 - begin1 << endl;
}

int main()
{
	//TestRBTree1();
	TestRBTree2();
	return 0;
}

// stl_set.h
template <class Key, class Compare = less<Key>, class Alloc = alloc>
class set {
public:
	// typedefs:
	typedef Key key_type;
	typedef Key value_type;
private:
	typedef rb_tree<key_type, value_type, //?
		identity<value_type>, key_compare, Alloc> rep_type; //?
	rep_type t; // red-black tree representing set
};
